#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 10;

int n;
int q[N], tq[N];
LL d[N], td[N];

LL f(LL d[]){
    LL res = 0;
    for(int i = 1; i <= n; i ++){
        if(d[i] > 0) res += d[i];
    }
    return res;
}

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> q[i];  
        tq[i] = q[i]; 
    }
    sort(tq + 1, tq + 1 + n);

    d[1] = q[1];
    td[1] = tq[1];

    for(int i = 2; i <= n; i ++){
        d[i] = q[i] - q[i - 1];
        td[i] = tq[i] - tq[i - 1];
    }

    LL k1 = f(d);
    LL k2 = f(td);

    if(k1 != k2){
        cout << "NO" << '\n';
    }else{
        cout << "YES" << '\n';
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}